package org.shoukaiseki.common.exception

import org.shoukaiseki.common.utils.StringUtils

//import javax.validation.constraints.NotNull

/**
 * 用于提示前端消息的虚拟异常
 * org.shoukaiseki.common.exception.MessageVirtualException
 * <br></br>
 *
 * @author shoukaiseki ブログ http://www.shoukaiseki.top/<br></br> E-メール jiang28555@Gmail.com<br></br>
 * @date 2020-12-21 11:35:40<br></br>
 */
open class MessageVirtualException : RuntimeException {
//    private override var message: String? = null

    constructor(message: String) : super(message) {
        this.message=message
    }

    constructor(message: String, t: Throwable?) : super(message, t) {
        this.message=message
    }

    override var message: String=""
        get() {
            if (super.cause != null && super.cause is MessageVirtualException) {
                return field + cause?.message

            } else {
                return field
            }
        }
        set(value) {field=value}


    open fun format(vararg params:Any):MessageVirtualException{
        if (this.message==null) {
            return this
        }
        //可变参数向下传递时加上 *
        this.message=StringUtils.format(super.message,*params)
        return this
    }

//    override fun getMessage(): String {
//        return if (message != null && super.cause != null) {
//            message + super.cause!!.message
//        } else message!!
//    }

}